package com.yurun.service.impl;

import com.yurun.entity.Category;
import com.yurun.exception.PersistenceException;
import com.yurun.mapper.CategoryMapper;
import com.yurun.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public void addCategory(Category category){
        if(categoryMapper.addCategory(category)!=1){
            throw new PersistenceException("添加类别失败");
        }
    }

    @Override
    public void deleteCategoryById(Long id){
        if(categoryMapper.deleteCategoryById(id)!=1){
            throw new PersistenceException("删除类别失败");
        }
    }

    @Override
    public void updateCategory(Category category){
        if(categoryMapper.updateCategory(category)!=1){
            throw new PersistenceException("更新类别失败");
        }
    }

    @Override
    public List<Category> getCategoryList(){
        return categoryMapper.getCategoryList();
    }
}
